package com.taoding.hfhclient.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.io.*;
import java.util.Properties;
/**
 * @author liuxinghong
 * @Description: 从本地配置文件读取当前农家乐的队列的key
 * @date 2019/8/28 002811:42
 */
@Component
@Slf4j
public  class ReadRoutingKey  {


    public static String read() {

        Properties prop = new Properties();
        try {
            //读取外部属性文件a.properties  File.separatorChar+
            InputStream in = new BufferedInputStream(new FileInputStream("key.properties"));
            prop.load(in);     ///加载属性列表
//            Iterator<String> it = prop.stringPropertyNames().iterator();
            String value = prop.getProperty("farmKey");
            log.info("从配置文件读出的属性: " + "farmKey"+" :"+ value);
            if (StringUtils.isEmpty(value)){
                throw new IOException("配置文件读取错误，farmKey未读到正确数据--文件内容："+prop.stringPropertyNames());
            }
            in.close();
            return value;
        } catch (FileNotFoundException e) {
            log.error("找不到配置文件[key.properties],请查看配置文件是否存在>>>>>>>>>>>>");
            log.error(e.getMessage());
        } catch (IOException e) {
            log.error("配置文件读取失败:");
            log.error(e.getMessage());
            e.printStackTrace();
        }
        return "0";
    }

}
